<?php

class UserModel extends RelationModel {
	/*
	 * 定义关联关系
	 */

	protected $_link = array(
		'tweets' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'tweets',
			'foreign_key' => 'user_id',
		),
		'comment' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'comment',
			'foreign_key' => 'user_id',
		),
		'message' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'message',
			'foreign_key' => 'user_id',
		),
		'notice' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'notice',
			'foreign_key' => 'user_id',
		),
		'report' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'report',
			'foreign_key' => 'user_id',
		),
		'school' => array(
			'mapping_type' => BELONGS_TO,
			'class_name' => 'school',
			'foreign_key' => 'school_id',
			'mapping_fields' => 'school_name',
			'as_fields' => 'school_name',
		),
		'user_follow' => array(
			'mapping_type' => MANY_TO_MANY,
			'class_name' => 'location',
			'foreign_key' => 'user_id',
			'relation_foreign_key' => 'location_id',
			'relation_table' => "agl_user_follow_location",
		),
	);
	/*
	 * 表单数据验证 
	 */
	protected $_validate = array(
		array('email', 'require', '邮箱必须填写', '0', 'regex'),
		array('email', 'email', '邮箱格式错误', '0','regex'),
		array('email', '', 'Email已存在！', '0', 'unique',1),
		array('password', 'require', '密码必须填写', 1),
		array('repassword', 'require', '确认密码不正确', '0', 'confirm'),
		array('password', 'checkPwd', '密码长度不足5位', '0', 'callback'),
	);

	function checkPwd() {
		$password = $_POST['password'];
		if (strlen($password) >= 5) {
			return true;
		} else {
			return false;
		}
	}

	/*
	 * 数据自动完成
	 */

	protected $_auto = array(
		array('create_time', 'time', 1, 'function'),
	);

	/*
	 * 表单项与字段的映射 
	 */
}

?>
